from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-08 14:15:36.513517
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 08, Jan, 2021
Time: 14:15:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -44.8138
Nobs: 165.000 HQIC: -45.8202
Log likelihood: 1819.78 FPE: 6.34502e-21
AIC: -46.5080 Det(Omega_mle): 3.73634e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.462794 0.153423 3.016 0.003
L1.Burgenland 0.135333 0.078544 1.723 0.085
L1.Kärnten -0.241968 0.063714 -3.798 0.000
L1.Niederösterreich 0.111982 0.182501 0.614 0.539
L1.Oberösterreich 0.245626 0.156320 1.571 0.116
L1.Salzburg 0.185367 0.082425 2.249 0.025
L1.Steiermark 0.078292 0.112677 0.695 0.487
L1.Tirol 0.146110 0.074757 1.954 0.051
L1.Vorarlberg 0.010757 0.071576 0.150 0.881
L1.Wien -0.117231 0.151896 -0.772 0.440
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.529664 0.197454 2.682 0.007
L1.Burgenland 0.009174 0.101085 0.091 0.928
L1.Kärnten 0.369390 0.081999 4.505 0.000
L1.Niederösterreich 0.129324 0.234878 0.551 0.582
L1.Oberösterreich -0.172846 0.201183 -0.859 0.390
L1.Salzburg 0.179663 0.106080 1.694 0.090
L1.Steiermark 0.240937 0.145015 1.661 0.097
L1.Tirol 0.141526 0.096211 1.471 0.141
L1.Vorarlberg 0.182754 0.092117 1.984 0.047
L1.Wien -0.593992 0.195489 -3.038 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296892 0.067380 4.406 0.000
L1.Burgenland 0.103663 0.034495 3.005 0.003
L1.Kärnten -0.024977 0.027982 -0.893 0.372
L1.Niederösterreich 0.066811 0.080151 0.834 0.405
L1.Oberösterreich 0.290633 0.068653 4.233 0.000
L1.Salzburg -0.001311 0.036200 -0.036 0.971
L1.Steiermark -0.024496 0.049486 -0.495 0.621
L1.Tirol 0.094994 0.032832 2.893 0.004
L1.Vorarlberg 0.128622 0.031435 4.092 0.000
L1.Wien 0.075421 0.066710 1.131 0.258
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208090 0.078447 2.653 0.008
L1.Burgenland -0.010690 0.040160 -0.266 0.790
L1.Kärnten 0.021518 0.032578 0.661 0.509
L1.Niederösterreich 0.036098 0.093315 0.387 0.699
L1.Oberösterreich 0.400977 0.079928 5.017 0.000
L1.Salzburg 0.093411 0.042145 2.216 0.027
L1.Steiermark 0.177556 0.057613 3.082 0.002
L1.Tirol 0.038421 0.038224 1.005 0.315
L1.Vorarlberg 0.101865 0.036597 2.783 0.005
L1.Wien -0.068874 0.077666 -0.887 0.375
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.570801 0.159841 3.571 0.000
L1.Burgenland 0.074739 0.081830 0.913 0.361
L1.Kärnten 0.001612 0.066379 0.024 0.981
L1.Niederösterreich -0.023031 0.190137 -0.121 0.904
L1.Oberösterreich 0.149038 0.162860 0.915 0.360
L1.Salzburg 0.049263 0.085873 0.574 0.566
L1.Steiermark 0.109200 0.117392 0.930 0.352
L1.Tirol 0.214737 0.077884 2.757 0.006
L1.Vorarlberg 0.012154 0.074570 0.163 0.871
L1.Wien -0.142066 0.158251 -0.898 0.369
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160467 0.112924 1.421 0.155
L1.Burgenland -0.026046 0.057811 -0.451 0.652
L1.Kärnten -0.012604 0.046895 -0.269 0.788
L1.Niederösterreich 0.182673 0.134326 1.360 0.174
L1.Oberösterreich 0.388359 0.115056 3.375 0.001
L1.Salzburg -0.031507 0.060667 -0.519 0.604
L1.Steiermark -0.048086 0.082934 -0.580 0.562
L1.Tirol 0.192465 0.055023 3.498 0.000
L1.Vorarlberg 0.045476 0.052682 0.863 0.388
L1.Wien 0.156585 0.111800 1.401 0.161
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.227210 0.143208 1.587 0.113
L1.Burgenland 0.060898 0.073315 0.831 0.406
L1.Kärnten -0.049576 0.059472 -0.834 0.404
L1.Niederösterreich -0.047868 0.170351 -0.281 0.779
L1.Oberösterreich -0.089866 0.145913 -0.616 0.538
L1.Salzburg 0.023500 0.076937 0.305 0.760
L1.Steiermark 0.382892 0.105175 3.641 0.000
L1.Tirol 0.508730 0.069780 7.291 0.000
L1.Vorarlberg 0.189644 0.066810 2.839 0.005
L1.Wien -0.202569 0.141783 -1.429 0.153
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125745 0.167048 0.753 0.452
L1.Burgenland 0.011102 0.085520 0.130 0.897
L1.Kärnten -0.110574 0.069372 -1.594 0.111
L1.Niederösterreich 0.207962 0.198710 1.047 0.295
L1.Oberösterreich 0.008564 0.170203 0.050 0.960
L1.Salzburg 0.220397 0.089745 2.456 0.014
L1.Steiermark 0.145580 0.122684 1.187 0.235
L1.Tirol 0.093705 0.081396 1.151 0.250
L1.Vorarlberg 0.016813 0.077933 0.216 0.829
L1.Wien 0.291017 0.165386 1.760 0.078
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.590482 0.091123 6.480 0.000
L1.Burgenland -0.020958 0.046650 -0.449 0.653
L1.Kärnten -0.001588 0.037842 -0.042 0.967
L1.Niederösterreich -0.012555 0.108394 -0.116 0.908
L1.Oberösterreich 0.279371 0.092844 3.009 0.003
L1.Salzburg 0.010206 0.048955 0.208 0.835
L1.Steiermark -0.001681 0.066923 -0.025 0.980
L1.Tirol 0.079387 0.044401 1.788 0.074
L1.Vorarlberg 0.170843 0.042511 4.019 0.000
L1.Wien -0.088704 0.090216 -0.983 0.325
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.147115 -0.002826 0.207244 0.244033 0.062665 0.092409 -0.076882 0.161035
Kärnten 0.147115 1.000000 -0.005248 0.186782 0.151360 -0.139105 0.160208 0.028372 0.304741
Niederösterreich -0.002826 -0.005248 1.000000 0.261559 0.079548 0.204864 0.098300 0.058927 0.352016
Oberösterreich 0.207244 0.186782 0.261559 1.000000 0.286398 0.298884 0.084719 0.076023 0.115073
Salzburg 0.244033 0.151360 0.079548 0.286398 1.000000 0.149997 0.074598 0.076859 -0.023247
Steiermark 0.062665 -0.139105 0.204864 0.298884 0.149997 1.000000 0.097641 0.090692 -0.126655
Tirol 0.092409 0.160208 0.098300 0.084719 0.074598 0.097641 1.000000 0.145351 0.135219
Vorarlberg -0.076882 0.028372 0.058927 0.076023 0.076859 0.090692 0.145351 1.000000 0.100102
Wien 0.161035 0.304741 0.352016 0.115073 -0.023247 -0.126655 0.135219 0.100102 1.000000